           package com.java.diagnostics.visualizer.parser.vgc.converters;
           
           public class Base60Formatter
           {
             private static final String ZERO = "0";
             private static final String COLON = ":";
             private static final String EMPTY = "";
           
             public static String format(double decimalValue, boolean formatToHours)
             {
               double largestUnit = Math.floor(decimalValue);
               double midUnit = (decimalValue - Math.floor(decimalValue)) * 60.0D;
               double smallestUnit;
               if (formatToHours) {
                  smallestUnit = (midUnit - Math.floor(midUnit)) * 60.0D;
                 smallestUnit = Math.round(smallestUnit);
                 if (smallestUnit > 59.0D) {
                   smallestUnit = 0.0D;
                   midUnit += 1.0D;
                 }
           
                 midUnit = Math.floor(midUnit);
               } else {
                 smallestUnit = 0.0D;
                 midUnit = Math.round(midUnit);
               }
               if (midUnit > 59.0D) {
                 midUnit = 0.0D;
                 largestUnit += 1.0D;
               }
               largestUnit = Math.floor(largestUnit);
               String largestUnitString = String.valueOf(largestUnit);
               String midUnitString = (midUnit < 10.0D ? "0" : "") + (int)midUnit;
               String smallestUnitString = (smallestUnit < 10.0D ? "0" : "") + 
                 (int)smallestUnit;
               String formattedString = largestUnitString + ":" + midUnitString + (
                 formatToHours ? ":" + smallestUnitString : "");
               return formattedString;
             }
           
             public static double parse(String stringRepresentation)
             {
               if (!stringRepresentation.contains(":")) {
                 return 0.0D;
               }
               String[] timeElements = stringRepresentation.split(":");
               if (timeElements.length == 2)
               {
                 double value = Double.parseDouble(timeElements[0]) + 
                   Double.parseDouble(timeElements[1]) / 60.0D;
                 return value;
               }
               if (timeElements.length == 3)
               {
                 double value = Double.parseDouble(timeElements[0]) + 
                   Double.parseDouble(timeElements[1]) / 60.0D + 
                   Double.parseDouble(timeElements[2]) / 60.0D / 60.0D;
                 return value;
               }
           
               return 0.0D;
             }
           }

